#include <iostream>
#include <glut.h>

using namespace std;

void displayFunc(void);
void reshape(GLsizei w, GLsizei h);
void timer(GLint timerValue);

GLint _millisecs = 33;
GLfloat _angulo = 0.0f;
GLfloat _anguloStep = 0.1f;

int main( int argc, char* argv[] )
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_MULTISAMPLE);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(650, 500);
	glutCreateWindow("Hola Mundo");
	glutDisplayFunc(displayFunc);
	glutReshapeFunc(reshape);
	glutTimerFunc(1, timer, _millisecs);

	glutMainLoop();
	return 0;
}

void displayFunc(void)
{
	glClearColor(0.1f, 0.1f, 0.3f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glPushMatrix();{
		glTranslatef(0.0f, 0.0f, -30.0f);
		glRotatef(_angulo, 0.3f, 0.8f, 0.2f);
		glutWireTeapot(10.0f);
	}
	glPopMatrix();

	glutSwapBuffers();
}

void reshape(GLsizei w, GLsizei h)
{
	GLfloat aspectRatio = 0.0f;
	aspectRatio = (GLfloat)w/(GLfloat)h;
	if(aspectRatio == 0.0f)
	{
		aspectRatio= 0.01f;
	}

	glViewport(0, 0, w, h);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45.0f, aspectRatio, 1.0f, 400.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void timer(GLint timerValue)
{
	_angulo += _anguloStep;
	glutPostRedisplay();
	glutTimerFunc(1, timer, _millisecs);
}